package com.adcok.lcdns.cronos.parser;

import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

import com.adcok.lcdns.cronos.data.CNLottoAdPartnerData;
import com.adcok.lcdns.cronos.datahandler.CNBaseDataParser;
import com.adcok.lcdns.cronos.datahandler.CNResultSet;

public class CNPartnerListParser extends CNBaseDataParser{
	protected void onParseContent(Element xmlObject, CNResultSet resultSet)
			throws Exception {
		
		NodeList nodeList = xmlObject.getElementsByTagName("partner");
		
		NodeList companyName = xmlObject.getElementsByTagName("companyName"); 
		NodeList companyContents = xmlObject.getElementsByTagName("companyContents");
		NodeList companyImg = xmlObject.getElementsByTagName("companyImg");
		
		NodeList totalCntNode = xmlObject.getElementsByTagName("totalCount");
		String totalCnt = totalCntNode.item(0).getFirstChild().getNodeValue();
		resultSet.setTotalCount(Integer.parseInt(totalCnt));
		
		int count = nodeList.getLength();
		
		for (int i = 0; i < count; i++)
		{
			Element elementData = (Element) nodeList.item(i);
			if (elementData == null)
				continue;
			
			CNLottoAdPartnerData dataSet = new CNLottoAdPartnerData();
			
			if(companyName.item(i).getFirstChild() != null)
				dataSet.partnerName = companyName.item(i).getFirstChild().getNodeValue();
			
			if(companyContents.item(i).getFirstChild() != null)
				dataSet.partnerContents = companyContents.item(i).getFirstChild().getNodeValue();
			
			if(companyImg.item(i).getFirstChild() != null)
				dataSet.partnerImg = companyImg.item(i).getFirstChild().getNodeValue();
			
			resultSet.addDataSet(dataSet);
		}
	}
}
